package com.woniu.service.Impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.woniu.dao.CreditOrderDao;
import com.woniu.dao.CreditRemitDao;
import com.woniu.entity.CreOrder;
import com.woniu.entity.CreRemit;
import com.woniu.service.CreditRemitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 打款
 */
@Service
public class CreditRemitServiceImpl implements CreditRemitService {

    @Autowired
    private CreditRemitDao creRemitDao;

    @Autowired
    private CreditOrderDao creditOrderDao;

    @Override
    public List<CreRemit> selectCreRemitList(CreRemit creRemit) {
        return creRemitDao.selectCreRemitList(creRemit);
    }

    @Override
    public int addPaymentData(CreRemit creRemit) {
        return creRemitDao.addPaymentData(creRemit);
    }

    @Override
    public AjaxResult remitOrderType(int orderId, int billId) {
        String username = SecurityUtils.getUsername();
        CreOrder creOrder = new CreOrder();
        // 更新打款表状态
        int j = creRemitDao.updateRemit(billId, username);
        creOrder.setOrderId(orderId);
        creOrder.setOrderStatus("1");
        // 更新订单表状态
        int i = creditOrderDao.updateCreOrder(creOrder);
        if (j == 1 && i == 1) {
            return AjaxResult.success("打款成功");
        }
        return AjaxResult.error("打款失败");
    }
}
